const mongoose = require('mongoose');

const backupSettingSchema = mongoose.Schema(
  {
    autoBackup: {
      type: Boolean,
      default: true,
    },
    frequency: {
      type: String,
      enum: ['daily', 'weekly', 'biweekly', 'monthly'],
      default: 'weekly',
    },
    retentionCount: {
      type: Number,
      default: 5,
      min: 1,
      max: 100,
    },
    backupTime: {
      type: String,
      default: '03:00', // 默认凌晨3点
      validate: {
        validator: function(v) {
          return /^([0-1][0-9]|2[0-3]):[0-5][0-9]$/.test(v); // 验证时间格式 HH:MM
        },
        message: '备份时间格式无效，请使用 HH:MM 格式'
      }
    },
    storageLocation: {
      type: String,
      enum: ['local', 'cloud', 'both'],
      default: 'local',
    },
    isDeleted: {
      type: Boolean,
      default: false,
    },
  },
  {
    timestamps: true,
  }
);

/**
 * @typedef BackupSetting
 */
const BackupSetting = mongoose.model('BackupSetting', backupSettingSchema, 'backup_settings');

module.exports = BackupSetting; 